package com.wx.spring.demo.controller;

import com.wx.spring.Person;
import com.wx.spring.annotations.*;
import com.wx.spring.demo.entity.User;
import com.wx.spring.demo.service.UserService;
import com.wx.spring.demo.service.impl.UserServiceImpl;
import com.wx.spring.mvc.MyModelAndView;
import com.wx.spring.mvc.MyModelMap;
import com.wx.spring.test.service.service.TestInterface;

/**
 * @ClassName TestController
 * @Author wx
 * @Description 测试控制层
 * @Date 2019-02-01-20:11
 */
@MyController
public class TestController {
    @MyAutowired
    private TestInterface TestImpl;

    @MyAutowired
    private UserService userServiceImpl;

    @MyRequestMapping(value = "/hello/success")
    public MyModelAndView testSuccess(@MyRequstParam(value = "name") String name){
        MyModelAndView myModelAndView = new MyModelAndView("success");
        MyModelMap myModelMap = new MyModelMap();
        myModelMap.put("test",name);
        myModelAndView.setModelMap(myModelMap);
        return myModelAndView;
    }


    @MyRequestMapping(value = "/hello/success2")
    public MyModelAndView testSuccess2(@MyModelAttribute(value = "Person") Person person){
        MyModelAndView myModelAndView = new MyModelAndView("success");
        MyModelMap myModelMap = new MyModelMap();
        System.out.println(person);
        myModelMap.put("test",person.getName());
        myModelAndView.setModelMap(myModelMap);
        return myModelAndView;
    }

    @MyRequestMapping(value = "/hello/user")
    public void getuser(@MyRequstParam(value = "userName") String userName,@MyRequstParam(value = "passWord") String passWord){
        User user = userServiceImpl.queryUser(userName, passWord);
        System.out.println(user);
    }

}
